<script>
import router from "@/router";


export default {
  name: "Add",
  data(){
    return {
      recode:
          {
            studentName:'',
            clazzname:'',
            registrant:'',
            reason:'',
            status:'',
            processor:'',
            handleTime:'',
            create_time:''
          },
      valizichan:{
        status:[{
          required:true,
          message:'请选处理状态',
          trigger:'change'
        }],
        studentName:[{
          required:true,
          message:'请输入学生姓名',
          trigger:'blur'
        }],
        clazzname:[{
          required:true,
          message:'请输入所在班级',
          trigger:'blur'
        }],
        processor:[{
          required:true,
          message:'请输入处理人',
          trigger:'blur'
        }],
        reason:[{
          required:true,
          message:'请输入处理原因',
          trigger:'blur'
        }],
        registrant:[{
          required:true,
          message:'请输入登记人',
          trigger:'blur'
        }],
        //时间选择器的验证
        handleTime:[{
          required:true,
          message:'请选择处理时间',
          trigger:'change'
        }],
        create_time:[{
          required:true,
          message:'请选择登记时间',
          trigger:'change'
        }]
      }
    }
  },
  methods: {
    add(){
      this.$refs['zhichanForm'].validate((valid)=>{
        if(valid){
         axios.post('http://localhost:8080/api/recode/add',this.$qs.stringify(this.recode)).then(res=> {
            if (res.data.code == 200) {
              this.$message.success('添加成功')
              router.push('/');
            } else {
            this.$message.error('添加失败')
            }
          })
              .catch(error=>{
               this.$message.error('添加失败')
              })
        }else{
          return false
        }
      })
    }
  }
}
</script>

<template>
  <el-row>
    <el-col :span="12">
      <el-form :model="recode" :rules="valizichan" ref="zhichanForm"  label-width="80px">
        <el-form-item label="处理状态" prop="status"  >
        <el-select v-model="recode.status" placeholder="请选择处理状态">
          <el-option label="已处理" value="1" ></el-option>
          <el-option label="未处理" value="2"></el-option>
        </el-select>
        </el-form-item>
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="recode.studentName"></el-input>
        </el-form-item>
        <el-form-item label="所在班级" prop="clazzname">
          <el-input v-model="recode.clazzname"></el-input>
        </el-form-item>
        <el-form-item label="违规违纪原因" prop="reason">
          <el-input v-model="recode.reason"></el-input>
        </el-form-item>
        <el-form-item label="登记人" prop="registrant">
          <el-input v-model="recode.registrant"></el-input>
        </el-form-item>
        <el-form-item label="登记时间" prop="create_time">
          <el-date-picker
              v-model="recode.create_time"
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理时间" prop="handleTime">
          <el-date-picker
              v-model="recode.handleTime"
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人" prop="processor">
          <el-input v-model="recode.processor"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add">添加</el-button>
          <el-button @click="$router.go(-1)">返回</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>
<style scoped>
</style>
